x86: Clean up and simplify rwlock implementation.
authorKeir Fraser <keir.fraser@citrix.com>
Sat, 13 Dec 2008 15:56:16 +0000 (15:56 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Sat, 13 Dec 2008 15:56:16 +0000 (15:56 +0000)
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen/arch/x86/Makefile
xen/arch/x86/rwlock.c [deleted file]
xen/include/asm-x86/rwlock.h [deleted file]
xen/include/asm-x86/spinlock.h

index 60ec345073b891fdc96adc7de7515b4c091e5bfc..b961585a33fdeafa1c61bec6cb757738d08edf9d 100644 (file)
@@ -37,7 +37,6 @@ obj-y += nmi.o
 obj-y += numa.o
 obj-y += pci.o
 obj-y += physdev.o
-obj-y += rwlock.o
 obj-y += setup.o
 obj-y += shutdown.o
 obj-y += smp.o
diff --git a/xen/arch/x86/rwlock.c b/xen/arch/x86/rwlock.c
deleted file mode 100644 (file)
index d8c1b7d..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <asm/atomic.h>
-#include <asm/rwlock.h>
-
-#if defined(CONFIG_SMP)
-asm(
-".align  4\n"
-".globl  __write_lock_failed\n"
-"__write_lock_failed:\n"
-"        " LOCK "addl    $" RW_LOCK_BIAS_STR ",(%"__OP"ax)\n"
-"1:      rep; nop\n"
-"        cmpl    $" RW_LOCK_BIAS_STR ",(%"__OP"ax)\n"
-"        jne     1b\n"
-"        " LOCK "subl    $" RW_LOCK_BIAS_STR ",(%"__OP"ax)\n"
-"        jnz     __write_lock_failed\n"
-"        ret\n"
-
-".align  4\n"
-".globl  __read_lock_failed\n"
-"__read_lock_failed:\n"
-"        lock ; incl     (%"__OP"ax)\n"
-"1:      rep; nop\n"
-"        cmpl    $1,(%"__OP"ax)\n"
-"        js      1b\n"
-"        lock ; decl     (%"__OP"ax)\n"
-"        js      __read_lock_failed\n"
-"        ret\n"
-);
-#endif
diff --git a/xen/include/asm-x86/rwlock.h b/xen/include/asm-x86/rwlock.h
deleted file mode 100644 (file)
index e4474d4..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/* include/asm-x86/rwlock.h
- *
- *     Helpers used by both rw spinlocks and rw semaphores.
- *
- *     Based in part on code from semaphore.h and
- *     spinlock.h Copyright 1996 Linus Torvalds.
- *
- *     Copyright 1999 Red Hat, Inc.
- *
- *     Written by Benjamin LaHaise.
- *
- *     This program is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License
- *     as published by the Free Software Foundation; either version
- *     2 of the License, or (at your option) any later version.
- */
-#ifndef _ASM_X86_RWLOCK_H
-#define _ASM_X86_RWLOCK_H
-
-#define RW_LOCK_BIAS            0x01000000
-#define RW_LOCK_BIAS_STR       "0x01000000"
-
-#define __build_read_lock_ptr(rw, helper)   \
-       asm volatile(LOCK "subl $1,(%0)\n\t" \
-                    "jns 1f\n\t" \
-                    "call " helper "\n\t" \
-                    "1:\n" \
-                    ::"a" (rw) : "memory")
-
-#define __build_read_lock_const(rw, helper)   \
-       asm volatile(LOCK "subl $1,%0\n\t" \
-                    "jns 1f\n\t" \
-                    "push %%"__OP"ax\n\t" \
-                    "lea %0,%%"__OP"ax\n\t" \
-                    "call " helper "\n\t" \
-                    "pop %%"__OP"ax\n\t" \
-                    "1:\n" \
-                    :"=m" (*(volatile int *)rw) : : "memory")
-
-#define __build_read_lock(rw, helper)  do { \
-                                               if (__builtin_constant_p(rw)) \
-                                                       __build_read_lock_const(rw, helper); \
-                                               else \
-                                                       __build_read_lock_ptr(rw, helper); \
-                                       } while (0)
-
-#define __build_write_lock_ptr(rw, helper) \
-       asm volatile(LOCK "subl $" RW_LOCK_BIAS_STR ",(%0)\n\t" \
-                    "jz 1f\n\t" \
-                    "call " helper "\n\t" \
-                    "1:\n" \
-                    ::"a" (rw) : "memory")
-
-#define __build_write_lock_const(rw, helper) \
-       asm volatile(LOCK "subl $" RW_LOCK_BIAS_STR ",(%0)\n\t" \
-                    "jz 1f\n\t" \
-                    "push %%"__OP"ax\n\t" \
-                    "lea %0,%%"__OP"ax\n\t" \
-                    "call " helper "\n\t" \
-                    "pop %%"__OP"ax\n\t" \
-                    "1:\n" \
-                    :"=m" (*(volatile int *)rw) : : "memory")
-
-#define __build_write_lock(rw, helper) do { \
-                                               if (__builtin_constant_p(rw)) \
-                                                       __build_write_lock_const(rw, helper); \
-                                               else \
-                                                       __build_write_lock_ptr(rw, helper); \
-                                       } while (0)
-
-#endif
index fd8c8ecfeef4512d5ee8b2222969cadad2053b0a..66c4d51435ff5c9728c462511a07bd42b3d93aaa 100644 (file)
@@ -4,7 +4,6 @@
 #include <xen/config.h>
 #include <xen/lib.h>
 #include <asm/atomic.h>
-#include <asm/rwlock.h>
 
 typedef struct {
     volatile s16 lock;
@@ -49,30 +48,50 @@ typedef struct {
     volatile unsigned int lock;
 } raw_rwlock_t;
 
+#define RW_LOCK_BIAS            0x01000000
 #define _RAW_RW_LOCK_UNLOCKED /*(raw_rwlock_t)*/ { RW_LOCK_BIAS }
 
-/*
- * On x86, we implement read-write locks as a 32-bit counter
- * with the high bit (sign) being the "contended" bit.
- */
 static always_inline void _raw_read_lock(raw_rwlock_t *rw)
 {
-    __build_read_lock(rw, "__read_lock_failed");
+    asm volatile (
+        "1:  lock; decl %0         \n"
+        "    jns 3f                \n"
+        "    lock; incl %0         \n"
+        "2:  rep; nop              \n"
+        "    cmpl $1,%0            \n"
+        "    js 2b                 \n"
+        "    jmp 1b                \n"
+        "3:"
+        : "=m" (rw->lock) : : "memory" );
 }
 
 static always_inline void _raw_write_lock(raw_rwlock_t *rw)
 {
-    __build_write_lock(rw, "__write_lock_failed");
+    asm volatile (
+        "1:  lock; subl %1,%0      \n"
+        "    jz 3f                 \n"
+        "    lock; addl %1,%0      \n"
+        "2:  rep; nop              \n"
+        "    cmpl %1,%0            \n"
+        "    jne 2b                \n"
+        "    jmp 1b                \n"
+        "3:"
+        : "=m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory" );
+}
+
+static always_inline void _raw_read_unlock(raw_rwlock_t *rw)
+{
+    asm volatile (
+        "lock ; incl %0"
+        : "=m" ((rw)->lock) : : "memory" );
 }
 
-#define _raw_read_unlock(rw)                    \
-    asm volatile (                              \
-        "lock ; incl %0" :                      \
-        "=m" ((rw)->lock) : : "memory" )
-#define _raw_write_unlock(rw)                           \
-    asm volatile (                                      \
-        "lock ; addl $" RW_LOCK_BIAS_STR ",%0" :        \
-        "=m" ((rw)->lock) : : "memory" )
+static always_inline void _raw_write_unlock(raw_rwlock_t *rw)
+{
+    asm volatile (
+        "lock ; addl %1,%0"
+        : "=m" ((rw)->lock) : "i" (RW_LOCK_BIAS) : "memory" );
+}
 
 #define _raw_rw_is_locked(x) ((x)->lock < RW_LOCK_BIAS)